<?php

class Hak_Akses_Model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }
    
    public function getDataAllMenu($whr) {
        $sql = "SELECT mt_menu.id_menu, mi.menu as menu_induk, mt_menu.menu from mt_menu
                LEFT JOIN mt_menu mi ON mi.id_menu = mt_menu.id_menu_induk";
        if ($whr != "") {
            $sql = $sql. " where " . $whr . " order by mt_menu.id_menu_induk, mt_menu.urutan ASC";
        } else {
            $sql = $sql. " order by mt_menu.id_menu_induk, mt_menu.urutan ASC";
        }

        $resultSet = $this->db->query($sql);
        return $resultSet;
    }

    public function getDataMenu($whr, $sc_pageslimit, $offset) {
        $sql = "SELECT mt_menu.id_menu, mi.menu as menu_induk, mt_menu.menu from mt_menu
                LEFT JOIN mt_menu mi ON mi.id_menu = mt_menu.id_menu_induk";
        if ($whr != "") {
            $sql = $sql. " where " . $whr . " order by mt_menu.id_menu_induk, mt_menu.urutan ASC
                        LIMIT " . $sc_pageslimit . " OFFSET " . $offset;
        } else {
            $sql = $sql. " order by mt_menu.id_menu_induk, mt_menu.urutan ASC "
                        . $sc_pageslimit . " OFFSET " . $offset;
        }

        $resultSet = $this->db->query($sql);
        return $resultSet;
    }

    public function getHakAksesUser($id_user) {
        $sql = "SELECT * FROM hak_akses WHERE id_user = '" . $id_user . "'";
        $resultSet = $this->db->query($sql);
        return $resultSet;
    }

    public function ChangeDataHakAkses($conds, $arrVals) {
        $this->db->where($conds, NULL, FALSE);
        $this->db->update('hak_akses', $arrVals);
    }

    public function addHakAkses($arrVals) {
        $this->db->insert('hak_akses', $arrVals);
    }

}

?>
